package com.bbs.dao.impl;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bbs.dao.BaseDao;
import com.bbs.dao.ReplyDao;
import com.bbs.model.Reply;
import com.bbs.util.PageSplitUtil;

public class ReplyDaoImpl extends BaseDao implements ReplyDao{

	public List<Reply> getReplyList(int id) {
		List<Reply> replyList;
		replyList=sqlSession.selectList("com.bbs.model.Reply.getReplyList",id);
		sqlSession.commit();
		sqlSession.close();
		return  replyList;
	}
	public ReplyDaoImpl() throws IOException {
		super();
	}

	public int save(Reply t) {
		int r=sqlSession.insert("com.bbs.model.Reply.insert",t);
		sqlSession.commit();
		sqlSession.close();
		return r;
	}

	public int delete(int id) {
		int r=sqlSession.delete("com.bbs.model.Reply.delete",id);
		sqlSession.commit();
		sqlSession.close();
		return r;
	}

	public int update(Reply t) {
		int r=sqlSession.update("com.bbs.model.Reply.update",t);
		sqlSession.commit();
		sqlSession.close();
		return r;
	}

	public Reply findById(int id) {
		Reply reply=sqlSession.selectOne("com.bbs.model.Reply.findById",id);
		sqlSession.commit();
		sqlSession.close();
		return reply;
	}
	
	public List<Reply> pageBrowse(PageSplitUtil psu,int id) {
		List<Reply> replyList;
		psu.setRecordCount((Integer) sqlSession.selectOne("com.bbs.model.Reply.getReplyCount",id));
		psu.comput();
		HashMap<String, Integer> paras=new HashMap<String,Integer>();
		paras.put("start", psu.getStart());
		paras.put("end", psu.getEnd());
		paras.put("topic_id", id);
		replyList=sqlSession.selectList("com.bbs.model.Reply.pageBrowse",paras);
		sqlSession.commit();
		sqlSession.close();
		return  replyList;
	}
	
	
	
}
